
package org.apache.solr.logging;

import org.apache.solr.common.util.SimpleOrderedMap;

/**
 * Wrapper class for Logger implementaions
 */
public abstract class LoggerInfo implements Comparable<LoggerInfo> {

    public static final String ROOT_NAME = "root";
    protected final String name;
    protected String level;

    public LoggerInfo(String name) {
        this.name = name;
    }

    public String getLevel() {
        return level;
    }

    public String getName() {
        return name;
    }

    public abstract boolean isSet();

    public SimpleOrderedMap<?> getInfo() {

        SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
        info.add("name", getName());
        info.add("level", getLevel());
        info.add("set", isSet());
        return info;
    }

    @Override
    public int compareTo(LoggerInfo other) {

        if(this.equals(other)) {
            return 0;
        }

        String tN = this.getName();
        String oN = other.getName();

        if(ROOT_NAME.equals(tN)) {
            return -1;
        }
        if(ROOT_NAME.equals(oN)) {
            return 1;
        }

        return tN.compareTo(oN);
    }
}